﻿namespace DesignModeConsole.行为型.解释器模式.加减乘除;

public interface IExpression1
{
    int Interpret();
}

public class NumberExpression : IExpression1
{
    private readonly int _number;

    public NumberExpression(int number)
    {
        _number = number;
    }

    public int Interpret()
    {
        return _number;
    }
}

/// <summary>
/// 加
/// </summary>
public class AdditionExpression : IExpression1
{
    private readonly IExpression1 _expression1;

    private readonly IExpression1 _expression2;

    public AdditionExpression(IExpression1 expression1, IExpression1 expression2)
    {
        _expression1 = expression1;
        _expression2 = expression2;
    }

    public int Interpret()
    {
        return _expression1.Interpret() + _expression2.Interpret();
    }
}

/// <summary>
/// 减
/// </summary>
public class SubtractionExpression : IExpression1
{
    private readonly IExpression1 _expression1;

    private readonly IExpression1 _expression2;

    public SubtractionExpression(IExpression1 expression1, IExpression1 expression2)
    {
        _expression1 = expression1;
        _expression2 = expression2;
    }

    public int Interpret()
    {
        return _expression1.Interpret() - _expression2.Interpret();
    }
}

/// <summary>
/// 乘
/// </summary>
public class MultiplicationExpression : IExpression1
{
    private readonly IExpression1 _expression1;

    private readonly IExpression1 _expression2;

    public MultiplicationExpression(IExpression1 expression1, IExpression1 expression2)
    {
        _expression1 = expression1;
        _expression2 = expression2;
    }

    public int Interpret()
    {
        return _expression1.Interpret() * _expression2.Interpret();
    }
}

/// <summary>
/// 除
/// </summary>
public class DivisionExpression : IExpression1
{
    private readonly IExpression1 _expression1;
    private readonly IExpression1 _expression2;

    public DivisionExpression(IExpression1 expression1, IExpression1 expression2)
    {
        _expression1 = expression1;
        _expression2 = expression2;
    }

    public int Interpret()
    {
        return _expression1.Interpret() / _expression2.Interpret();
    }
}